﻿///<reference path='jquery-1.4.4-vsdoc.js'/>
////显示系统时间
function changeTime() {
    var curdate = new Date().format("yyyy年MM月dd日  hh:mm:ss");
    $("#timemsg").html("<font style='font-weight:normal;color:#fff;font-size:12'>当前时间：" + curdate + "</font>");
}

function addTab(subtitle, url, icon) {

    var tt = $('#main-center');
    if (tt.tabs('exists', subtitle)) {
        tt.tabs('select', subtitle);
        $('#mm-tabupdate').click();

    } else {

        tt.tabs('add', {
            title: subtitle,
            content: createFrame(url+""),
            closable: true,
            icon: icon
        });

    }
    tabClose();
}
function createFrame(url) {
    var s = '<iframe scrolling="auto" frameborder="0" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
    return s;
}
function tabClose() {
    var tt = $('#main-center');   
    /*双击关闭TAB选项卡*/
    $(".tabs-inner").dblclick(function() {
        var subtitle = $(this).children(".tabs-closable").text();       
            tt.tabs('close', subtitle);
        
    })
    /*为选项卡绑定右键*/
    $(".tabs-inner").bind('contextmenu', function(e) {
       var subtitle = $(this).children(".tabs-closable").text();       
            $('#mm').menu('show', {
                left: e.pageX,
                top: e.pageY
            });
            $('#mm').data("currtab", subtitle);
            tt.tabs('select', subtitle);
            return false;
        
    });
}
//绑定右键菜单事件
function tabCloseEven() {
    var tt = $('#main-center');
    //刷新
    $('#mm-tabupdate').click(function() {
        var currTab = tt.tabs('getSelected');
        var url = $(currTab.panel('options').content).attr('src');
        tt.tabs('update', {
            tab: currTab,
            options: {
                content: createFrame(url)
            }
        })
        //        }
    })
    //关闭当前
    $('#mm-tabclose').click(function() {
        var currtab_title = $('#mm').data("currtab");
        tt.tabs('close', currtab_title);
    })
    //全部关闭
    $('#mm-tabcloseall').click(function() {
        $('.tabs-inner span').each(function(i, n) {
            var t = $(n).text();
            tt.tabs('close', t);
        });
    });
    //关闭除当前之外的TAB
    $('#mm-tabcloseother').click(function() {
        $('#mm-tabcloseright').click();
        $('#mm-tabcloseleft').click();
    });
    //关闭当前右侧的TAB
    $('#mm-tabcloseright').click(function() {
        var nextall = $('.tabs-selected').nextAll();
        if (nextall.length == 0) {

            return false;
        }
        nextall.each(function(i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            tt.tabs('close', t);
        });
        return false;
    });
    //关闭当前左侧的TAB
    $('#mm-tabcloseleft').click(function() {
        var prevall = $('.tabs-selected').prevAll();
        if (prevall.length == 0) {
            return false;
        }
        prevall.each(function(i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            tt.tabs('close', t);
        });
        return false;
    });

    //退出
    $("#mm-exit").click(function() {
        $('#mm').menu('hide');

    })
}

//异步菜单
function CreatMenu() {
    var menu = $('#menu');
    menu.tree({   
                 checkbox: false,
                 url: '../Admin/CreateMenu/0',
                 animate: true,  
                onBeforeExpand:function(node,param){
                menu.tree('options').url = "../Admin/CreateMenu/" + node.id+""; // change the url                       
                    //param.myattr = 'test';    // or change request parameter
                },
                onClick: function(node) {
                if (node.addr!= "")
                     addTab(node.text,node.addr,"icon-doc"); 
                 }   
             });     
}

$(document).ready(function() {
    CreatMenu();
    tabClose();
    tabCloseEven();
    //    addTab("首页", "Defualt", "icon-home");
    //日期时间格式
    Date.prototype.format = function(format) {
        var o = {
            "M+": this.getMonth() + 1, //month   
            "d+": this.getDate(),    //day   
            "h+": this.getHours(),   //hour   
            "m+": this.getMinutes(), //minute   
            "s+": this.getSeconds(), //second   
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter   
            "S": this.getMilliseconds() //millisecond   
        }
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
            (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o) if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
                    RegExp.$1.length == 1 ? o[k] :
                    ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    };
    setInterval(changeTime, 1000);
});


  